package demo.using.java8;

import java.util.Optional;

/**
 * @author : GuoFei
 * @date : 2019/2/26 15:36
 */
public class OptionalTest {
    public static void main(String args) {
        System.out.println("begin");
        try {
            int test1 = 29;
            String test2 = "nihao";
            Integer test3 = null;
            System.out.println(Optional.of(test1).get());
            System.out.println(Optional.of(test2).get());
            System.out.println(Optional.of(test3).get());
        } catch (Exception e) {
            System.out.println("---------------");
            System.out.println(e.getMessage());
            System.out.println("---------------");
            System.out.println(e.getStackTrace());
            System.out.println("---------------");
            System.out.println(e.getCause());
            System.out.println("---------------");
            System.out.println(e.getLocalizedMessage());
            System.out.println("---------------");
            System.out.println(e.getSuppressed());
            System.out.println("---------------");
            System.out.println(e.getClass());
            System.out.println("---------------");
            e.printStackTrace();
        }
        System.out.println("end");
    }

    public static void main(String[] args) {
        Integer test3;
        System.out.println(Optional.empty().orElse(0));
        test3 = 2;
        System.out.println(Optional.of(test3).orElse(0));
    }
}
